package com.smrtcold.dev.utils;

import java.util.HashMap;

public class R extends HashMap<String, Object>  {
    private static final long serialVersionUID = 1L;
    public R() { put("code", 200);  put("msg", "操作成功!");}
    public static R ok() { return new R(); }
    public static R ok(String msg) { R r = new R();  r.put("msg", msg); return r;}

    public static R put(Object value) { return R.ok().put("data", value); }
    public static R pageData(Object page) { return R.ok().put("pageData", page);}

    public static R err() {  return err(500, "操作失败！请稍后重试！"); }
    public static R err(String msg) {  return err(500, msg);}
    public static R err(int code, String msg) { return new R().put("code", code).put("msg", msg); }

    public static R error425(String msg) { return err(425, msg);}
    public static R error500() {return err(500, "服务器繁忙！请稍后重试"); }

    @Override
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public boolean isOk(){
        return 200==(Integer) get("code");
    }
}
